<template>
	<div>
		<!-- 顶部选项卡 -->
		<scroll-view class="pagecontrol-top-scroll" scroll-x="true" scroll-with-animation
			:scroll-into-view="scrollInto">
			<view class="pagecontrol-top-title">
				<view v-for="(items, index) in itemsArr" :key="index" class="pagecontrol-top-text"
					@click="changeTab(index)" :id="'tab' + index">
					<view :class="tabIndex === index ? 'pagecontrol-top-selected' : 'pagecontrol-top-normal'">
						{{ items }}
					</view>
					<view class="pagecontrol-bottom-line"
						:class="tabIndex === index ? 'pagecontrol-bottom-line-show' : 'pagecontrol-bottom-line-visibility'">
					</view>
				</view>
			</view>
		</scroll-view>
		<!-- 内容 -->
		<swiper :duration="150" :current="tabIndex" @change="onChangeTab" :style="'height:' + scrollH + 'px;'">
			<swiper-item>
				<scroll-view scroll-y="true" show :style="'height:' + scrollH + 'px;'">
					<!--基本资料-->
					<view style="padding-bottom: 100px;">
						<view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;">
							<uni-forms ref="form" :modelValue="formData" :rules="rules"  labelWidth="90px">
								<uni-forms-item label="承运商名称" name="carrierName" required>
									<uni-easyinput type="text" v-model="formData.carrierName" placeholder="请输入承运商名称" />
								</uni-forms-item>
								<uni-forms-item label="承运商类型" name="carrierType" required>
									<uni-data-select v-model="formData.carrierType" :localdata="carrierType"
										style="background-color: white;" />
								</uni-forms-item>
								<uni-forms-item label="统一社会信用代码" name="registeredNo" required>
									<uni-easyinput type="text" v-model="formData.registeredNo" placeholder="请输入统一社会信用代码" />
								</uni-forms-item>
								<uni-forms-item label="法人姓名" name="legalPersonName">
									<uni-easyinput type="text" v-model="formData.legalPersonName" placeholder="请输入法人姓名" />
								</uni-forms-item>
								<uni-forms-item label="法人身份证" name="legalPersonIdCard">
									<uni-easyinput type="number" v-model="formData.legalPersonIdCard" placeholder="请输入法人身份证" />
								</uni-forms-item>
								<uni-forms-item label="办公电话" name="officePhone">
									<uni-easyinput type="number" v-model="formData.officePhone" placeholder="请输入办公电话" />
								</uni-forms-item>
								<uni-forms-item label="成立时间" name="establishTime">
									<uni-datetime-picker type="datetime" v-model="formData.establishTime" />
								</uni-forms-item>
								<uni-forms-item label="注册资本(万元)" name="registeredCapital">
									<uni-easyinput type="text" v-model="formData.registeredCapital" placeholder="请输入注册资本(万元)" />
								</uni-forms-item>
								<uni-forms-item label="经营地址"  name="businessDistrictId" required>
									<uni-data-picker placeholder="请选择地址" popup-title="请选择所在地区" :localdata="DistrictId"
										style="background-color: white;" v-model="formData.businessDistrictId">
									</uni-data-picker>
									<view style="margin-top: 20px;">
										<uni-easyinput type="text"
											v-model="formData.businessAddress" placeholder="请输入详细地址" />
									</view>
								</uni-forms-item>
								<uni-forms-item label="联系人" name="contactPerson" required>
									<uni-easyinput type="text" v-model="formData.contactPerson" placeholder="请输入联系人" />
								</uni-forms-item>
								<uni-forms-item label="职务" name="contactPosition">
									<uni-easyinput type="text" v-model="formData.contactPosition" placeholder="请输入职务" />
								</uni-forms-item>
								<uni-forms-item label="联系电话" name="phone" required>
									<uni-easyinput type="number" v-model="formData.phone" placeholder="请输入联系电话" />
								</uni-forms-item>
								<uni-forms-item label="电子邮箱" name="email">
									<uni-easyinput type="text" v-model="formData.email" placeholder="请输入电子邮箱" />
								</uni-forms-item>
								<uni-forms-item label="通讯地址"  name="locationDistrictId" required>
									<uni-data-picker placeholder="请选择地址" popup-title="请选择所在地区" :localdata="DistrictId"
										style="background-color: white;" v-model="formData.locationDistrictId">
									</uni-data-picker>
									<view style="margin-top: 20px;">
										<uni-easyinput type="text"
											v-model="formData.locationAddress" placeholder="请输入详细地址" />
									</view>
								</uni-forms-item>
								<uni-forms-item label="自有车辆" name="ownVehicle">
									<uni-easyinput type="text" v-model="formData.ownVehicle" placeholder="辆" />
								</uni-forms-item>
								<uni-forms-item label="外部车辆" name="externalVehicle">
									<uni-easyinput type="text" v-model="formData.externalVehicle" placeholder="辆" />
								</uni-forms-item>
								<uni-forms-item label="相关资料">
									<myfilepicker :limit="'1'" :imageStyles="imageStyles" :fileIdString="formData.workCardAttachment" :fileExtname="'png,jpg,jpeg'" :fileMediatype="'image'"  @transFileIdString="getFileIdString_workCardAttachment"
											:title="'*点击上传工牌名片，支持png/jpg/jpeg，最多可上传1个附件*'"><uni-icons type="cloud-upload" size="18"></uni-icons>工牌名片</myfilepicker>
									<view style="margin-top: 10px;">
										<myfilepicker :limit="'1'" :imageStyles="imageStyles" :fileIdString="formData.idCardFrontAttachment" :fileExtname="'png,jpg,jpeg'" :fileMediatype="'image'"  @transFileIdString="getFileIdString_idCardFrontAttachment"
												:title="'*点击上传身份证(正面)，支持png/jpg/jpeg，最多可上传1个附件*'"><uni-icons type="cloud-upload" size="18"></uni-icons>身份证(正面)</myfilepicker>
									</view>
									<view style="margin-top: 10px;">
										<myfilepicker :limit="'1'" :imageStyles="imageStyles" :fileIdString="formData.idCardBackAttachment" :fileExtname="'png,jpg,jpeg'" :fileMediatype="'image'"  @transFileIdString="getFileIdString_idCardBackAttachment"
												:title="'*点击上传身份证(反面)，支持png/jpg/jpeg，最多可上传1个附件*'"><uni-icons type="cloud-upload" size="18"></uni-icons>身份证(反面)</myfilepicker>
									</view>
								    <view style="margin-top: 10px;">
										<myfilepicker :limit="'1'" :imageStyles="imageStyles" :fileIdString="formData.businessLicenseAttachment" :fileExtname="'png,jpg,jpeg'" :fileMediatype="'image'"  @transFileIdString="getFileIdString_businessLicenseAttachment"
												:title="'*点击上传营业执照，支持png/jpg/jpeg，最多可上传1个附件*'"><uni-icons type="cloud-upload" size="18"></uni-icons>营业执照</myfilepicker>
									</view>
									<view style="margin-top: 10px;">
										<myfilepicker :limit="'3'"  :fileIdString="formData.otherAttachment" :fileExtname="'pdf,png,gif,jpg,jpeg,doc,docx'" :fileMediatype="'all'"  @transFileIdString="getFileIdString_otherAttachment"
												:title="'*点击上传其他附件，支持pdf/doc/docx/jpg/jpeg/png/gif，最多可上传3个附件*'"></myfilepicker>
									</view>
									
								</uni-forms-item>
								<uni-forms-item label="备注" name="remark">
									<uni-easyinput type="textarea" v-model="formData.remark" placeholder="承运商相关备注说明" />
								</uni-forms-item>
							</uni-forms>
							
						</view>
					</view>
				</scroll-view>
				<view
					style="background-color: #ffffff;z-index: 3;height: 70px;width:100%;position: fixed;bottom: 0;display: flex;box-shadow: 0px 0px 11px rgba(0, 0, 0, 0.1);">
					<view
						style="display: flex;align-items: center;width: 100%;height: 60px;justify-content: center;">
						<view v-if="carrierId==''" @click="submit()" hover-class="buttonHover"
							style="height: 35px;background-color: #bf5f09;color: #ffffff;width: 100px;display: flex;justify-content: center;align-items: center;border-radius: 4px;">
							确定新增</view>
						<view v-else @click="submit_update()" hover-class="buttonHover"
							style="height: 35px;background-color: #bf5f09;color: #ffffff;width: 100px;display: flex;justify-content: center;align-items: center;border-radius: 4px;">
							保存</view>
					</view>
				</view>
			</swiper-item>
			<swiper-item>
				<scroll-view scroll-y="true" show :style="'height:' + scrollH + 'px;'">
					<!--合同信息-->
					<view style="padding-bottom: 100px;">
						<view class="carrier" v-for="(item,index) in carrierContractList" :key="index">
							<view style="border-bottom: 0.5px solid rgb(237, 237, 237);">
								<view class="contract" style="background-color: #d9d9d9;width: 100px;height: 30px;border-radius: 20px 0 0;font-weight: bold;font-size: 15px;display: flex;justify-content: center;align-items: center;">
									<text style="display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 1;overflow: hidden;width: 80px;text-align: center;">
										{{item.contractName}}
									</text>
								</view>
							</view>
							<view style="margin: 10px;">
								<view style="display: flex;flex-direction: row;justify-content: space-between;">
									<text>{{item.oilCardRatio}}%油卡</text>
									<text>{{item.settlementMethod}}{{item.settlementDays}}天</text>
								</view>
								<view>
									<text>{{item.applicationScope}}</text>
								</view>
								<view style="display: flex;flex-direction: row;justify-content: space-between;">
									<text>{{item.contractDeposit}}元保证金&ensp;&ensp;已缴纳</text>
									<text>{{item.startTime}}~{{item.endTime}}</text>
								</view>
								<view style="margin-top: 10px;">
									<!--这里是文件-->
									<previewfilepicker  @clickFile="clickFile_attachments"  readonly limit="3"  :value="fileList_attachments[index]" file-extname="pdf,png,gif,jpg,jpeg,doc,docx" file-mediatype="all"></previewfilepicker>
								</view>
								<view style="border-top: 0.5px solid rgb(237, 237, 237);position: relative;margin-bottom: 30px;">
									<button @click="editContract(index)" hover-class="buttonHover" style="position: absolute;text-align: center;right: 60px;top:6px;border: 1rpx solid #bf5f09;color:#bf5f09;border-radius: 8px;font-size: 12px;display: flex;align-items: center;height: 26px;">编辑</button>
									<button @click="deleteContract(index)" hover-class="buttonHover" style="position: absolute;text-align: center;right: 0;top:6px;border: 1rpx solid #bf5f09;color:#bf5f09;border-radius: 8px;font-size: 12px;display: flex;align-items: center;height: 26px;">删除</button>
								</view>
							</view>
							
						</view>
						<!-- <view @click="addContract" hover-class="buttonHover" style="position: fixed;left: 50%;transform:translateX(-50%);bottom:10px;width: 100px;height:35px;color:#ffffff;background-color:#bf5f09;border-radius: 4px;display:flex;justify-content: center;align-items: center;">
							新增合同
						</view> -->
						<view @click="addContract" hover-class="buttonHover" style="position: fixed;right: 15px;bottom:100px;width: 50px;height:50px;color:#ffffff;background-color:#bf5f09;border-radius: 50%;display:flex;justify-content: center;align-items: center;box-shadow: 0 1px 5px 2px rgba(0, 0, 0, 0.3);">
							<uni-icons type="plusempty" size="30" color="#ffffff"></uni-icons>
						</view>
					</view>
				</scroll-view>
				<view
					style="background-color: #ffffff;z-index: 3;height: 70px;width:100%;position: fixed;bottom: 0;display: flex;box-shadow: 0px 0px 11px rgba(0, 0, 0, 0.1);">
					<view
						style="display: flex;align-items: center;width: 100%;height: 60px;justify-content: center;">
						<view v-if="carrierId==''" @click="submit()" hover-class="buttonHover"
							style="height: 35px;background-color: #bf5f09;color: #ffffff;width: 100px;display: flex;justify-content: center;align-items: center;border-radius: 4px;">
							确定新增</view>
						<view v-else @click="submit_update()" hover-class="buttonHover"
							style="height: 35px;background-color: #bf5f09;color: #ffffff;width: 100px;display: flex;justify-content: center;align-items: center;border-radius: 4px;">
							保存</view>
					</view>
				</view>
			</swiper-item>
			<swiper-item>
				<scroll-view scroll-y="true" show :style="'height:' + scrollH + 'px;'">
					<!--常跑路线-->
					<view  style="padding-bottom: 100px;">
						<view v-for="(item,index) in carrierLineList" :key="index" style="display: flex;flex-direction: row;padding: 10px;justify-content: space-between;background-color: white;margin: 10px;border-radius: 12px;">
							<view style="display: flex;flex-direction: column;">
								<view style="display: flex;align-items: center;">
									<view style="width: 25px;height: 25px;border: 1px solid rgb(91, 86, 86);display: flex;justify-content: center;align-items: center;">
										起
									</view>
									<view style="display: flex;flex-direction: column;margin-left: 10px;margin-right: 10px">
										<text>{{item.departDistrictName}}</text>
									</view>
								</view>
							    <view style="display: flex;align-items: center;margin-top: 15px;">
									<view style="width: 25px;height: 25px;border: 1px solid rgb(91, 86, 86);display: flex;justify-content: center;align-items: center;">
										止
									</view>
									<view style="display: flex;flex-direction: column;margin-left: 10px;margin-right: 10px">
										<text>{{item.arriveDistrictName}}</text>
									</view>
									
								</view>
							</view>
							<view style="display: flex;flex-direction: column;justify-content: space-around;">
								<button @click="editDriverLineList(index)" hover-class="buttonHover" type="primary" 
									style="color:#ffffff;background-color:#bf5f09;font-size: 13px;width: 60px;height: 30px;">编辑</button>
								<button @click="deleteDriverLineList(index)" hover-class="buttonHover" type="primary"
									style="color:#ffffff;background-color:#bf5f09;font-size: 13px;width: 60px;height: 30px;">删除</button>
							</view>
							
						</view>
						<!-- <view @click="addLine" hover-class="buttonHover" style="position: fixed;left: 50%;transform:translateX(-50%);bottom:10px;width: 100px;height:35px;color:#ffffff;background-color:#bf5f09;border-radius: 4px;display:flex;justify-content: center;align-items: center;">
							新增线路
						</view> -->
						<view @click="addLine" hover-class="buttonHover" style="position: fixed;right: 15px;bottom:100px;width: 50px;height:50px;color:#ffffff;background-color:#bf5f09;border-radius: 50%;display:flex;justify-content: center;align-items: center;box-shadow: 0 1px 5px 2px rgba(0, 0, 0, 0.3);">
							<uni-icons type="plusempty" size="30" color="#ffffff"></uni-icons>
						</view>
					</view>
				</scroll-view>
				<view
					style="background-color: #ffffff;z-index: 3;height: 70px;width:100%;position: fixed;bottom: 0;display: flex;box-shadow: 0px 0px 11px rgba(0, 0, 0, 0.1);">
					<view
						style="display: flex;align-items: center;width: 100%;height: 60px;justify-content: center;">
						<view v-if="carrierId==''" @click="submit()" hover-class="buttonHover"
							style="height: 35px;background-color: #bf5f09;color: #ffffff;width: 100px;display: flex;justify-content: center;align-items: center;border-radius: 4px;">
							确定新增</view>
						<view v-else @click="submit_update()" hover-class="buttonHover"
							style="height: 35px;background-color: #bf5f09;color: #ffffff;width: 100px;display: flex;justify-content: center;align-items: center;border-radius: 4px;">
							保存</view>
					</view>
				</view>
			</swiper-item>
		</swiper>
		
		<!-- 新增路线弹窗 -->
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="取消" confirmText="确定" title="新增路线" @confirm="dialogConfirm" :before-close="true" @close="this.$refs.alertDialog.close()">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 116px;">
					<view style="display: flex;flex-direction: column;width: 100%;">
						<uni-forms labelWidth="75px">
							<uni-forms-item label="起始地址">
								<uni-data-picker @change="getDepartDistrictName" placeholder="请选择起始地址" popup-title="请选择所在地区" :localdata="DistrictId"
									style="background-color: white;" v-model="departDistrict">
								</uni-data-picker>
							</uni-forms-item>
							<uni-forms-item label="目的地址">
								<uni-data-picker @change="getArriveDistrictName" placeholder="请选择目的地址" popup-title="请选择所在地区" :localdata="DistrictId"
									style="background-color: white;" v-model="arriveDistrict">
								</uni-data-picker>
							</uni-forms-item>
						</uni-forms>
					</view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
	</div>
</template>

<script>
	import {
		getCarrierDetails,
		addCarrier,
		updateCarrierProfile
	} from '@/api/system/carrier.js'
	import {getFileList} from '@/api/system/uploadFile.js'
	import {getDicts,getAllAddressTree} from '@/api/system/dict.js'
	import myfilepicker from '@/components/uploadFile/uploadFile.vue'
	import previewfilepicker from '@/components/my-file-picker.vue'
	
	export default {
		components: {
			myfilepicker,
			previewfilepicker
		},
		data() {
			return {
				itemsArr: ['基本资料', '合同信息','常跑路线'],
				tabIndex: 0,
				scrollH: 700,
				scrollInto: '',
				formData: {
					carrierName: '',
					carrierType: '',
					registeredNo: '',
					legalPersonName: '',
					legalPersonIdCard: '',
					officePhone: '',
					establishTime: '',
					registeredCapital: '',
					businessDistrictId:'',
					businessAddress:'',
					contactPerson: '',
					contactPosition: '',
					phone: '',
					email:'',
					locationDistrictId: '',
					locationAddress: '',
					ownVehicle:'',
					externalVehicle:'',
					
					idCardFrontAttachment:'',
					idCardBackAttachment:'',
					businessLicenseAttachment:'',
					workCardAttachment:'',
					otherAttachment:'',
					remark:'',
				},
				// 校验规则
				rules: {
					carrierName: {
						rules: [{
							required: true,
							errorMessage: '请输入承运商名称',
						}]
					},
					carrierType: {
						rules: [{
							required: true,
							errorMessage: '请选择承运商类型',
						}]
					},
					registeredNo: {
						rules: [{
							required: true,
							errorMessage: '请输入工商注册号',
						}]
					},
					businessDistrictId: {
						rules: [{
							required: true,
							errorMessage: '请选择经营地址',
						}]
					},
					contactPerson: {
						rules: [{
							required: true,
							errorMessage: '请输入联系人',
						}]
					},
					phone: {
						rules: [{
							required: true,
							errorMessage: '请输入联系电话',
						},
						{
						    pattern: '^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$',
						    errorMessage: '电话格式不正确'
						}
						]
					},
					locationDistrictId: {
						rules: [{
							required: true,
							errorMessage: '请选择通讯地址',
						}]
					},
				},
				//地区下拉框
				DistrictId: [],
				//下拉框 ->承运商类型
				carrierType: [],
				imageStyles: {
					width: '100%',
					height: 200,
					border: {
						radius: '4px'
					}
				},
				carrierId:'',
				//合同集合
				carrierContractList:[],
				
				//常跑路线
				carrierLineList:[],
				
				//弹窗的起始地址
				departDistrict:'',
				departDistrictName:'',
				arriveDistrict:'',
				arriveDistrictName:'',
				
				//编辑序号index
				editDriverLineIndex:'',
				
				//合同附件
				fileList_attachments:[]
			}
		},
		onLoad(e) {
			uni.getSystemInfo({
				success: res => {
					this.scrollH = res.windowHeight - 40;
				}
			});
			
			if (e.carrierId) {
				//设置顶部导航栏标题
				uni.setNavigationBarTitle({
					title: '编辑承运商'
				})
			
				uni.showLoading({
					title: '正在加载',
				})
				this.carrierId = e.carrierId
				//获取承运商详情
				getCarrierDetails(e.carrierId).then(res => {
					uni.hideLoading()
					if (res.code == '200') {
						this.formData = res.data

						this.carrierContractList=this.formData.carrierContractList||[]
						//合同附件列表回显
						if(this.carrierContractList.length!==0)
						{
							this.carrierContractList.forEach((item,index)=>{
								if(item.attachments!==null)
								{
									let AllFileUrl=[];
									AllFileUrl=item.attachments.split(",")
									getFileList(AllFileUrl).then(res2=>{
										this.fileList_attachments[index]= res2.data.map((item2,index)=>{
											return {
												id:item2.id,
												url: item2.url,
												extname: item2.fileType,
												name: item2.name,
											}
										})
									})
								}
							})
						}
						this.carrierLineList=this.formData.carrierLineList||[]
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
				})
			}
		},
		created() {
			//获取承运商类型下拉框
			getDicts('carrier_type').then(res=>{
				this.carrierType=res.data.map(item=>{
					return {
						value:item.dictValue,
						text:item.dictLabel
					}
				})
			})
			
			//获取全国地址信息->地区下拉框
			getAllAddressTree().then(res=>{
				this.DistrictId=res.data
			})
		},
		methods: {
			//接收文件传递的id字符串集合
			getFileIdString_workCardAttachment(fileIds){
				this.formData.workCardAttachment=fileIds
			},
			//接收文件传递的id字符串集合
			getFileIdString_idCardFrontAttachment(fileIds){
				this.formData.idCardFrontAttachment=fileIds
			},
			//接收文件传递的id字符串集合
			getFileIdString_idCardBackAttachment(fileIds){
				this.formData.idCardBackAttachment=fileIds
			},
			//接收文件传递的id字符串集合
			getFileIdString_businessLicenseAttachment(fileIds){
				this.formData.businessLicenseAttachment=fileIds
			},
			//接收文件传递的id字符串集合
			getFileIdString_otherAttachment(fileIds){
				this.formData.otherAttachment=fileIds
			},
			//接受保存合同后的数据
			otherFun(bookList,index) {
				if(bookList){
					if(index)//编辑
					{
						this.carrierContractList.splice(index,1,bookList)
					}
					else   //新增
					{
						this.carrierContractList.push(bookList)
					}
					
					//合同附件列表回显
					if(this.carrierContractList.length!==0)
					{
						this.carrierContractList.forEach((item,index)=>{
							if(item.attachments!==null)
							{
								let AllFileUrl=[];
								AllFileUrl=item.attachments.split(",")
								getFileList(AllFileUrl).then(res2=>{
									this.fileList_attachments[index]= res2.data.map((item,index)=>{
										return {
											id:item.id,
											url: item.url,
											extname: item.fileType,
											name: item.name,
										}
									})
								})
							}
						})
					}
					
				}
				else{
					return
				}
			},
			// 切换选项
			changeTab(index) {
				if (this.tabIndex === index) {
					return;
				}
				this.tabIndex = index;
				// 滚动到指定元素
				this.scrollInto = 'tab' + index;
			},
			// 监听滑动
			onChangeTab(e) {
				uni.showLoading({
					title: '正在加载',
				})
				setTimeout(function() {
					uni.hideLoading()
				}, 500);
				this.changeTab(e.detail.current);
			},
			//预览合同附件
			clickFile_attachments(e){
				if(e.tempFile.extname=='png'||e.tempFile.extname=='jpg'||e.tempFile.extname=='jpeg')  //预览图片
				{
					uni.previewImage({
					    current: 0, //预览图片的下标
					    urls: [e.tempFile.url] //预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
					})
				}
				else  //pdf,png,gif,jpg,doc
				{
					uni.navigateTo({
						url: "/pages/common/fileView",
						success: (res) => {
							// 通过eventChannel向被打开页面传送数据
							res.eventChannel.emit("dataFun", {
								data: {
									name: e.tempFile.name+'预览',
									fileSrc: e.tempFile.url,
									isFileDown: true
								},
							});
						},
					});
				}
			},
			//编辑合同
			editContract(index){
				uni.navigateTo({
					url:'/pages-user/user/addCarrier/addContract?contractDetails='+encodeURIComponent(JSON.stringify(this.carrierContractList[index]))+'&index='+index
				})
			},
			//删除合同
			deleteContract(index){
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定删除此合同？',
					success: function (res) {
						if (res.confirm) {
							that.carrierContractList.splice(index,1)
						}
					}
				});
			},
			//弹出层
			addContract(){
				if(this.carrierContractList.length>=1)
				{
					uni.showToast({
						icon:'none',
						title:'只能设置1份合同'
					})
					return 
				}
				uni.navigateTo({
					url:'/pages-user/user/addCarrier/addContract'
				})
			},
			//编辑线路
			editDriverLineList(index){
				//为了回显到弹窗上
				this.editDriverLineIndex=index
				this.arriveDistrict=this.carrierLineList[index].arriveDistrict
				this.arriveDistrictName=this.carrierLineList[index].arriveDistrictName
				this.departDistrict=this.carrierLineList[index].departDistrict
				this.departDistrictName=this.carrierLineList[index].departDistrictName
				this.$refs.alertDialog.open()
			},
			//删除线路
			deleteDriverLineList(index){
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定删除此线路？',
					success: function (res) {
						if (res.confirm) {
							that.carrierLineList.splice(index,1)
						}
					}
				});
			},
			//新增路线
			addLine(){
				this.arriveDistrict=''
				this.departDistrict=''
				this.departDistrictName=''
				this.arriveDistrictName=''
				this.editDriverLineIndex=''
				this.$refs.alertDialog.open()
			},
			//确认新增路线
			dialogConfirm() {
				if(!this.departDistrict)
				{
					uni.showToast({
						title: '起始地址不能为空',
						icon:'none'
					})
					return
				}
				if(!this.arriveDistrict)
				{
					uni.showToast({
						title: '目的地址不能为空',
						icon:'none'
					})
					return
				}
				if(this.editDriverLineIndex==='')  //新增
				{
					this.carrierLineList.push({
						arriveDistrict:this.arriveDistrict,
						arriveDistrictName:this.arriveDistrictName,
						departDistrict:this.departDistrict,
						departDistrictName:this.departDistrictName
					})
				}
				else   //编辑
				{
					this.carrierLineList.splice(this.editDriverLineIndex,1,{
						arriveDistrict:this.arriveDistrict,
						arriveDistrictName:this.arriveDistrictName,
						carrierDriverId:this.formData.carrierId,
						departDistrict:this.departDistrict,
						departDistrictName:this.departDistrictName,
					})
				}
				//关闭弹窗
				this.$refs.alertDialog.close()
			},
			//新增路线弹窗选择起始地址
			getDepartDistrictName(e){
				if(e.detail.value.length) this.departDistrictName=e.detail.value[0].text+e.detail.value[1].text+e.detail.value[2].text;
				else this.departDistrictName='';
				
			},
			//新增路线弹窗选择目的地址
			getArriveDistrictName(e){
				if(e.detail.value.length) this.arriveDistrictName=e.detail.value[0].text+e.detail.value[1].text+e.detail.value[2].text;
				else this.arriveDistrictName='';
			},
			//提交新增承运商
			submit() {
				let that = this
				this.$refs.form.validate().then(res => {
					uni.showLoading({
						title: '正在提交...',
					})
					//合同
					that.formData.carrierContractList=that.carrierContractList
					//路线
					that.formData.carrierLineList=that.carrierLineList
					
					addCarrier(that.formData).then(res => {
						uni.hideLoading()
						if (res.code == '200') {
							uni.showToast({
								title: '提交成功',
								icon: 'none'
							})
							let pages = getCurrentPages(); // 获取当前页面栈的实例，以数组形式按栈的顺序给出，第一个元素为首页，最后一个元素为当前页面。
							let nowPage = pages[pages.length - 1]; //当前页页面实例
							let prevPage = pages[pages.length - 2]; //上一页页面实例
							prevPage.$vm.otherFun('2') // 給上一頁綁定方法otherFun,傳參0（tabIndex：0）
							uni.navigateBack({
								delta: 1 // 可以不傳delta值，默認為1
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg
							})
						}
					})
				}).catch(err => {
					uni.showToast({
						title: err[0].errorMessage,
						icon: 'none'
					})
				})
			},
			//修改承运商
			submit_update() {
				let that = this
				this.$refs.form.validate().then(res => {
					uni.showLoading({
						title: '正在提交...',
					})
					//合同
					that.formData.carrierContractList=that.carrierContractList
					//路线
					that.formData.carrierLineList=that.carrierLineList
					
					//id
					that.formData.carrierId = that.carrierId
					updateCarrierProfile(that.formData).then(res => {
						uni.hideLoading()
						if (res.code == '200') {
							uni.showToast({
								title: '修改成功',
								icon: 'none'
							})
							let pages = getCurrentPages(); // 获取当前页面栈的实例，以数组形式按栈的顺序给出，第一个元素为首页，最后一个元素为当前页面。
							let nowPage = pages[pages.length - 1]; //当前页页面实例
							let prevPage = pages[pages.length - 2]; //上一页页面实例
							prevPage.$vm.otherFun('2') // 給上一頁綁定方法otherFun,傳參0（tabIndex：0）
							setTimeout(() => {
								uni.navigateBack({
									delta: 1 // 可以不傳delta值，默認為1
								})
							}, 1000)
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg
							})
						}
					})
				}).catch(err => {
					uni.showToast({
						title: err[0].errorMessage,
						icon: 'none'
					})
				})
			},
		},
	}
</script>

<style scoped>
	.pagecontrol-top-scroll {
		height: 40px;
		width: 100%;
		white-space: nowrap;
		box-sizing: border-box;
		border-bottom: 1rpx solid #ededed;
		background-color: #f8f8f8;
	}

	.pagecontrol-top-title {
		height: 100%;
		width: 100%;
		display: flex;
		justify-content: space-around;
	}

	.pagecontrol-top-text {
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		text-align: center;
	}

	.pagecontrol-top-normal {
		color: #656565;
		font-size: 16px;
	}

	.pagecontrol-top-selected {
		color: #000000;
		font-weight: bold;
		font-size: 16px;
	}

	.pagecontrol-bottom-line {
		width: 33vw;
		height: 3px;
		margin-top: 8px;
		background-color: #bf5f09;
		border-radius: 11px;
	}

	.pagecontrol-bottom-line-show {
		visibility: visible;
	}

	.pagecontrol-bottom-line-visibility {
		visibility: hidden;
	}

	.buttonHover {
		opacity: 0.6;
	}
	::v-deep .file-title{
	    font-size: 12px;
	    color: #333;
	}
	
	
	.carrier{
		min-height: 150px;
		margin: 10px;
		border-radius: 20px;
		display: flex;
		flex-direction: column;
		border-bottom: 1px solid #ededed;
		background-color: #ffffff;
	}
	.contract::after{
	    content: "";
	    position: absolute;
	    width: 0;
	    height: 0;
	    left: 110px;
	    border-right: 3px solid transparent;
	    border-bottom: 30px solid transparent;
	    border-left: 16px solid #d9d9d9;
	    }
		
	::v-deep .uni-forms-item__content{
		width: 0vw;
	}
</style>